package com.example.controller;

import com.example.common.Result;
import com.example.entity.Member;
import com.example.service.MemberService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/member")
public class MemberController {

    @Resource
    private MemberService memberService;

    @PostMapping("/add")
    public Result add(@RequestBody Member member) {
        memberService.add(member);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody Member member) {
        memberService.update(member);
        return Result.success();
    }

    @DeleteMapping("/deleteById")
    public Result deleteById(@RequestParam Integer id) {
        memberService.deleteById(id);
        return Result.success();
    }

    @DeleteMapping("/deleteById/{id}")
    public Result delete(@PathVariable Integer id) {
        memberService.deleteById(id);
        return Result.success();
    }

    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam Integer pageNum,
                             @RequestParam Integer pageSize,
                             Member member) {
        PageInfo<Member> pageInfo = memberService.selectPage(pageNum, pageSize, member);
        return Result.success(pageInfo);
    }

    @PostMapping("/login")
    public Result login(@RequestBody Member member) {
        Member dbMember = memberService.login(member);
        return Result.success(dbMember);
    }

    @PostMapping("/updatePassword")
    public Result updatePassword(@RequestBody Member member) {
        memberService.updatePassword(member);
        return Result.success();
    }

}
